package com.linkwechat;

import java.net.InetAddress;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.core.env.Environment;

import com.linkwechat.common.config.fegin.FeginConfig;

import lombok.extern.slf4j.Slf4j;

/**
 * 网关启动程序
 *
 * @author leejoker
 */
@Slf4j
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class })
@EnableFeignClients(basePackages = "com.linkwechat.**", defaultConfiguration = FeginConfig.class)
public class LinkWechatGatewayApplication {
	public static void main(String[] args) throws Exception {
		System.setProperty("file.encoding", "UTF-8");

		Environment env = new SpringApplicationBuilder(LinkWechatGatewayApplication.class) //
				.properties("spring.config.name:bootstrap", "config/run/bootstrap.yml") //
				.properties("spring.application.name=linkwe-gateway").build().run(args).getEnvironment();

		String envPort = env.getProperty("server.port");
		String envContext = env.getProperty("server.contextPath",
				env.getProperty("server.servlet.context-path", env.getProperty("server.servlet.contextPath")));
		String nacos = env.getProperty("spring.cloud.nacos.config.server-addr");
		String namespace = env.getProperty("spring.cloud.nacos.config.namespace");
		// 项目端口
		String port = envPort == null ? "8899" : envPort;
		String context = envContext == null ? "" : envContext;
		String ip = InetAddress.getLocalHost().getHostAddress();
		log.info("------------------Access URLs:----------------------------");
		log.info("Local-API: \thttp://{}:{}{}/doc.html", ip, port, context);
		log.info("nacos-URL: \thttp://{}/nacos/#/configurationManagement?namespace={}", nacos, namespace);
		log.info("----------------------------------------------------------");

		System.out.println("(♥◠‿◠)ﾉﾞ  LinkWe-gateway启动成功   ლ(´ڡ`ლ)ﾞ ");
	}
}
